package com.bjtu.laorenyouhao.guanliyuan.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bjtu.laorenyouhao.guanliyuan.entity.LaifangInfoEntity;
import com.bjtu.laorenyouhao.guanliyuan.service.LaifangInfoService;
import com.bjtu.common.utils.PageUtils;
import com.bjtu.common.utils.R;



/**
 * 来访信息表
 *
 * @author yangyalong
 * @email yangyalong@gmail.com
 * @date 2021-07-08 21:01:02
 */
@RestController
@RequestMapping("guanliyuan/laifanginfo")
public class LaifangInfoController {
    @Autowired
    private LaifangInfoService laifangInfoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = laifangInfoService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 取得义工的来访id
     * @param id
     * @return
     */
    @RequestMapping("/yigong/{id}")
    public R yighong(@PathVariable("id") Long id){
        List<LaifangInfoEntity> laifangInfoEntityList = laifangInfoService.list(
                new QueryWrapper<LaifangInfoEntity>().eq("laifang_type",2).eq("people_id",id)
        );

        return R.ok().put("laifang", laifangInfoEntityList);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		LaifangInfoEntity laifangInfo = laifangInfoService.getById(id);

        return R.ok().put("laifangInfo", laifangInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody LaifangInfoEntity laifangInfo){
		laifangInfoService.save(laifangInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody LaifangInfoEntity laifangInfo){
		laifangInfoService.updateById(laifangInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		laifangInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
